﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace Moving03.Services
{
    /// <summary>
    /// Summary description for XemGiaVanChuyen
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class XemGiaVanChuyen : System.Web.Services.WebService
    {
        DataClasses1DataContext context = new DataClasses1DataContext();
        public string GetTenQuocGia(int id)
        {
            string tenQuocGia = "";
            var query = from qg in context.DanhSachQuocGias
                        where qg.Id_MaQGia == id
                        select qg;
            foreach (var i in query)
            {
                tenQuocGia = i.TenQuocGia;
            }
            return tenQuocGia;
        }
        [WebMethod]
        public classXemGiaVanChuyen[] XemGiaVanChuyenNgoaiNuoc()
        {
            

            var query = from cost in context.ChiPhiDiaDiemNuocNgoais
                        join qg1 in context.DanhSachQuocGias on cost.Id_QuocGia1 equals qg1.Id_MaQGia
                        join qg2 in context.DanhSachQuocGias on cost.Id_QuocGia2 equals qg2.Id_MaQGia
                        select cost;
            int j = 0;
            classXemGiaVanChuyen[] arr = new classXemGiaVanChuyen[query.Count()];
            foreach (var i in query)
            {
                classXemGiaVanChuyen nuocNgoai = new classXemGiaVanChuyen();
                nuocNgoai.Ten = i.Ten;
                nuocNgoai.TenQuocGia1 = GetTenQuocGia((int)i.Id_QuocGia1);
                nuocNgoai.TenQuocGia2 = GetTenQuocGia((int)i.Id_QuocGia2);
                nuocNgoai.Gia = (float)i.GiaBinhThuong;
                nuocNgoai.Nhanh = (int)i.GiaNhanh;
                arr[j] = nuocNgoai;
                j++;
            }
            return arr;
        }
    }
}
